package org.zjh.view.findpassword;

import org.zjh.controller.action.CancelJbtLis;
import org.zjh.controller.listener.UpdatePlayerOkLis;

import javax.swing.*;
import java.awt.*;

import static org.zjh.constant.ImageConstant.*;

/**
 * 找回密码面板
 */
public class UpdatePlayerInfoPanel extends JPanel {


    private JLabel securityIssuesLabel1;
    private JLabel securityIssuesLabel2;
    private JTextField answerTextField1;
    private JTextField answerTextField2;
    private JPasswordField resetPasswordField;
    private JPasswordField okResetPasswordField;
    private JTextField newNicknameField;
    private JLabel okJLabel;
    private JButton cancelJbt;

    public UpdatePlayerInfoPanel() {
        init();
        addListener();
    }

    /**
     * 初始化
     */
    private void init() {
        setLayout(null);

        //创建标签
        securityIssuesLabel1 = new JLabel("密保问题一：");
        securityIssuesLabel2 = new JLabel("密保问题二：");
        JLabel answerLabel1 = new JLabel("答案");
        JLabel answerLabel2 = new JLabel("答案");
        JLabel newNicknameLabel = new JLabel("新昵称（可选）");
        JLabel resetPassword = new JLabel("重置密码");
        JLabel okResetPassword = new JLabel("确认密码");
        securityIssuesLabel1.setBounds(300, 50, 500, 50);
        answerLabel1.setBounds(375, 100, 150, 50);
        securityIssuesLabel2.setBounds(300, 150, 500, 50);
        answerLabel2.setBounds(375, 200, 150, 50);
        newNicknameLabel.setBounds(250,250,175,50);
        resetPassword.setBounds(325, 300, 150, 50);
        okResetPassword.setBounds(325, 350, 150, 50);

        //设置标签字体
        securityIssuesLabel1.setFont(new Font("黑体", Font.PLAIN, 25));
        securityIssuesLabel2.setFont(new Font("黑体", Font.PLAIN, 25));
        answerLabel1.setFont(new Font("黑体", Font.PLAIN, 25));
        answerLabel2.setFont(new Font("黑体", Font.PLAIN, 25));
        newNicknameLabel.setFont(new Font("黑体", Font.PLAIN, 25));
        resetPassword.setFont(new Font("黑体", Font.PLAIN, 25));
        okResetPassword.setFont(new Font("黑体", Font.PLAIN, 25));

        //字体颜色加粗
        securityIssuesLabel1.setForeground(Color.BLACK);
        securityIssuesLabel2.setForeground(Color.BLACK);
        answerLabel1.setForeground(Color.BLACK);
        answerLabel2.setForeground(Color.BLACK);
        newNicknameLabel.setForeground(Color.BLACK);
        resetPassword.setForeground(Color.BLACK);
        okResetPassword.setForeground(Color.BLACK);

        //创建文本框
        answerTextField1 = new JTextField();
        answerTextField2 = new JTextField();
        newNicknameField = new JTextField();
        resetPasswordField = new JPasswordField();
        okResetPasswordField = new JPasswordField();
        //为文本框设置属性
        answerTextField1.setBounds(450, 110, 100, 25);
        answerTextField2.setBounds(450, 210, 100, 25);
        newNicknameField.setBounds(450, 260, 100, 25);
        resetPasswordField.setBounds(450, 310, 100, 25);
        okResetPasswordField.setBounds(450, 360, 100, 25);

        okJLabel = new JLabel(OK_BUTTON_IMAGE);
        cancelJbt = new JButton(CANCEL_IMAGE);


        okJLabel.setBounds(400, 450, 120, 50);
        cancelJbt.setBounds(650, 450, 80, 50);

        //将创建的标签 文本框 按钮 添加到面板
        add(securityIssuesLabel1);
        add(securityIssuesLabel2);
        add(answerLabel1);
        add(answerLabel2);
        add(resetPassword);
        add(okResetPassword);
        add(answerTextField1);
        add(answerTextField2);
        add(newNicknameLabel);
        add(newNicknameField);
        add(resetPasswordField);
        add(okResetPasswordField);
        add(okJLabel);
        add(cancelJbt);
    }

    /**
     * 刷新页面方法
     */
    public void refresh() {
        answerTextField1.setText("");
        answerTextField2.setText("");
        newNicknameField.setText("");
        resetPasswordField.setText("");
        okResetPasswordField.setText("");
    }


    /**
     * 添加监听器
     */
    private void addListener() {
        //设置取消按钮动作监听指令
        cancelJbt.setActionCommand("UpdateCancel");
        //取消按钮添加监听
        cancelJbt.addActionListener(CancelJbtLis.getInstance());
        okJLabel.addMouseListener(UpdatePlayerOkLis.getInstance());
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(FIND_PASSWORD_IMAGE.getImage(), 0, 0, FIND_PASSWORD_IMAGE.getIconWidth(), FIND_PASSWORD_IMAGE.getIconHeight(), null);
    }


    public JLabel getSecurityIssuesLabel1() {
        return securityIssuesLabel1;
    }

    public JLabel getSecurityIssuesLabel2() {
        return securityIssuesLabel2;
    }

    public JTextField getAnswerTextField1() {
        return answerTextField1;
    }

    public JTextField getAnswerTextField2() {
        return answerTextField2;
    }

    public JPasswordField getResetPasswordField() {
        return resetPasswordField;
    }

    public JPasswordField getOkResetPasswordField() {
        return okResetPasswordField;
    }

    public JTextField getNewNicknameField() {
        return newNicknameField;
    }
}
